package com.pureut.storage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.PickingPurchaseDetail;
import com.pureut.storage.dto.PickingPurchaseDetailListDto;
import com.pureut.storage.mapper.PickingPurchaseDetailMapper;
import com.pureut.storage.service.PickingPurchaseDetailService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: YSL
 * @Date: 2023/2/2 14:46
 * @Desc: 采购退货明细
 */
@Service
public class PickingPurchaseDetailServiceImpl extends ServiceImpl<PickingPurchaseDetailMapper, PickingPurchaseDetail> implements PickingPurchaseDetailService {

    @Resource
    PickingPurchaseDetailMapper pickingPurchaseDetailMapper;

    /**
     *
     * @param docNum
     * @return
     */
    @Override
    public List<PickingPurchaseDetailListDto> getPurchaseList(String docNum) {


        // 采购退货明细物料状态
        List<SysDictData> statusArray = DictUtils.getDictCache("picking_purchase_detail");
        Map<String, String> materialMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        List<PickingPurchaseDetailListDto> purchaseList = pickingPurchaseDetailMapper.getPurchaseList(docNum);
        for (PickingPurchaseDetailListDto purchaseDetailListDto : purchaseList){
            // 物料状态
            purchaseDetailListDto.setWodStatusDict(materialMap.get(String.valueOf(purchaseDetailListDto.getWodStatus())));

        }

        return purchaseList;
    }
}
